package cn.ygh.bbo.system.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;

import static cn.ygh.bbo.framerwork.config.constant.WebConstant.CODE_CACHE_NAME;

/**
 * @author ygh
 * @Desc 验证码工具
 * @date 2019/11/27
 */
@Service
public class CodeService {

    @Autowired
    CacheManager cacheManager;

    /**
     * 保存code
     * @param token
     * @param code
     * @return
     */
    public void saveCode(String token,String code){
        cacheManager.getCache(CODE_CACHE_NAME).put(token,code);
    }


    /**
     * 获得code
     * @param token
     * @return
     */
    public String getCode(String token){
        return cacheManager.getCache(CODE_CACHE_NAME).get(token,String.class);
    }

    /**
     * 删除code
     * @param token
     */
    public void removeCode(String token){
        cacheManager.getCache(CODE_CACHE_NAME).evict(token);
    }


}
